package com.ztorn.model;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.stream.Collectors;

@Data
@TableName("t_user")
public class User implements UserDetails {

    private Integer id;

    private String account;

    private BigDecimal accountBalance;

    private String address;

    private BigDecimal annualLeave;

    private String appType;

    private BigDecimal assignedto;

    private String avatar;

    private String bco;

    private Date birthday;

    private String businesslicence;

    private String businesslicencepic;

    private BigDecimal childrenQty;

    private String clockinSite;

    private String co;

    private String company;

    private String contract;

    private Date createtime;

    private String creator;

    private BigDecimal deptid;

    private String deputyAbsence;

    private String div;

    private BigDecimal education;

    private String email;

    private String emergencyContact;

    private String emergencyTel;

    private Date employmentDate;

    private Date expirationDate;

    private String graduateInstitutions;

    private String householdAddr;

    private String idcard;

    private String idcardpic;

    private String idcardtype;

    private BigDecimal isAbsence;

    private String lastName;

    private BigDecimal leaveInLieu;

    private String majors;

    private String maritalStatus;

    private String modifier;

    private Date modifyDate;

    private String name;

    private String nationality;

    private String nativePlace;

    private String officeTel;

    private String password;

    private BigDecimal pendingAmount;

    private String phone;

    private String photoKey;

    private String position;

    private String qqId;

    private String relationship;

    private String resumeKey;

    private String roleid;

    private String salt;

    private String sclinkman;

    private BigDecimal sex;

    private String signatureKey;

    private BigDecimal status;

    private String supervisor;

    private String userId;

    private String usertype;

    private BigDecimal version;

    private String wechatId;

    private String whse;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Arrays.stream(this.roleid.split(",")).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.account;
    }

    @Override
    public boolean isAccountNonExpired() {
        if(this.status.compareTo(BigDecimal.ONE) == 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        if(this.status.compareTo(BigDecimal.ONE) == 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        if(this.status.compareTo(BigDecimal.ONE) == 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean isEnabled() {
        if(this.status.compareTo(BigDecimal.ONE) == 0){
            return true;
        }
        return false;
    }
}
